<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <p>1</p>
  <p>2</p>
  <p>3</p>
  <p>4</p>
  <p>5</p>
  <p>6</p>
  <p>7</p>
  <p>8</p>
  <p>9</p>
  <p>10</p>
  <script>
    window.onload = () => {
      let ps = document.getElementsByTagName('p')
      let bp = function () {
        console.log(ps)
        for (let i = 0; i < ps.length; i++) {
          ps[i].onclick = function () {
            alert('点击成功')
          }
        }
      }
      bp()
    }
  </script>
</body>

</html>